import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
import clientConfig from './client_config';
import * as path from 'path';

export default (appInfo: EggAppInfo) => {


  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + 'apaas_1618080055099_6915';

  // add your egg config in here
  config.middleware = ['auth'];

  config.session = {
    renew: true
  };

  config.multipart = {
    mode: 'file',
    fileSize: 10000000000
  };

  config.view = {
    defaultViewEngine: 'nunjucks',
    defaultExtension: '.html',
    cache: false,
    mapping: {
      '.html': 'nunjucks'
    }
  };

  config.security = {
    csrf: false
  };

  config.mysql = {
    // 单数据库信息配置
    client: clientConfig.mysql,
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false
  };

  config.io = {
    init: {
    },
    // transports: ['websocket'],
    namespace: {
      '/': {
        connectionMiddleware: [],
        packetMiddleware: []
      }
    }
  };

  config.redis = {
    client: clientConfig.redis
  };

  config.oss = {
    client: clientConfig.oss
  };

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`
  };

  config.auth = {
    exclude: ['/api/version/issue', '/login', '/api/version/download']
  };

  config.static = {
    prefix: '/public/',
    dir: path.join(appInfo.baseDir, 'app/public'),
    dynamic: true,
    prload: false
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig
  };
};
